package models

import "el/bootstrap/driver"

type Visitor struct {
	Id        int    `gorm:"column:id" db:"id" json:"id" form:"id"`
	Name      string `gorm:"column:name" db:"name" json:"name" form:"name"`                     //名称
	Avator    string `gorm:"column:avator" db:"avator" json:"avator" form:"avator"`             //头像
	SourceIp  string `gorm:"column:source_ip" db:"source_ip" json:"source_ip" form:"source_ip"` //服务ip
	ToId      string `gorm:"column:to_id" db:"to_id" json:"to_id" form:"to_id"`                 //客服id
	CreatedAt MyTime `gorm:"column:created_at" db:"created_at" json:"created_at" form:"created_at"`
	UpdatedAt MyTime `gorm:"column:updated_at" db:"updated_at" json:"updated_at" form:"updated_at"`
	VisitorId string `gorm:"column:visitor_id" db:"visitor_id" json:"visitor_id" form:"visitor_id"` //uuid
	Status    int8   `gorm:"column:status" db:"status" json:"status" form:"status"`                 //1上线0下线
	Refer     string `gorm:"column:refer" db:"refer" json:"refer" form:"refer"`                     //来源
	City      string `gorm:"column:city" db:"city" json:"city" form:"city"`                         //客户端城市
	ClientIp  string `gorm:"column:client_ip" db:"client_ip" json:"client_ip" form:"client_ip"`     //客户端ip
	Extra     string `gorm:"column:extra" db:"extra" json:"extra" form:"extra"`                     //扩展信息，来源和地址
}

func (Visitor) TableName() string {
	return "visitor"
}

func (my *Visitor) InfoByVisitorId() error {
	return driver.Grom.Where("visitor_id = ?", my.VisitorId).First(my).Error
}

func (my *Visitor) Create() error {
	return driver.Grom.Create(&my).Error
}

func (my *Visitor) Update() error {
	return driver.Grom.Save(&my).Error
}

func NewVisitor() *Visitor {
	return &Visitor{}
}
